#1
"""
from faker import Faker
def shuai(n):
    for i in range(n):
        a = Faker(locale='zh_cn')
        print(a.name())
shuai(5)
"""

#2
"""
import faker
from faker import Faker
import random
b=random.randint(1,120)
a=Faker(locale='zh_cn')
print(a.address())
with open('info.txt','w',encoding='utf-8') as f:
    for i in range(100):
        a = Faker(locale='zh_cn')
        f.write('姓名:'+a.name()+' '+'年龄:'+str(random.randint(1,120))+' '+'手机号:'+a.phone_number()+' '+'身份证号：'+a.ssn(min_age=18,max_age=90)+' '+'地址:'+a.address()+"\n")
"""

#3
"""
with open('student.txt','w',encoding='utf-8') as f:
    f.write('{zhangshan:'+'30'+',')
with open('student.txt','a',encoding='utf-8') as f:
    f.write('lisi:'+'50'+',')
    f.write('wangwu:'+'60'+',')
    f.write('lifei:'+'70}'+'\n')
    f.write('zhangshan:' + '30' + '\n')
    f.write('lisi:' + '50' + '\n')
    f.write('wangwu:' + '60' + '\n')
    f.write('lifei:' + '70')
"""

"""
result = {}
with open('student1.txt','r',encoding='utf-8') as f:
    for i in f.readlines():
        result[i.split(':')[0]] = int(i.split(":")[1].strip())
print(result)
"""
#转字典的方法
"""
a=['asd',123]
b={}
b[a[0]]=a[1]
print(b)
"""

#4
# nums=[123,123,234,234,33,33,55,6,6]

# count_dict = {}
# def singleNumber(nums):              # 创建一个空字典，用于存储元素的出现次数
#                                        # 遍历数组，更新字典中元素的出现次数
#       for num in nums:
#           if num in count_dict:
#              count_dict[num] += 1
#       else:
#              count_dict[num] = 1            # 找到出现一次的元素
#       for key, value in count_dict.items():
#           if value == 1:
#
#               return key                  # 示例
# nums = [4, 3, 2, 1, 4, 3, 2, 8, 7, 7, 6, 6, 5, 5, 1, 8,9]
# result = singleNumber(nums)
# print(result)



# nums=[11,22,33,77,77,44,33,22,11,44,3,5,8]
# for i in nums:
#     if nums.count(i) == 1:
#         print(i)

#5、输入：["1","a","b","3","5","8","_"] 想要提取里面得数字，并保存到一个列表中
"""
c=["1","a","b","3","5","8","_"]
b=[]
for i in c:
    if i in "0123456789":
        b.append(i)
print(b)
"""

# 6、写函数,函数接收的4个参数分别是:姓名,性别(默认为男),年龄,地址
# 用户通过input输入这4个内容(支持持续输入,Q或q退出),并传递给函数
# 函数接收到这些内容,将其追加到student_msg文件中
"""
def shuai(name, age, adress, sex="男"):
    with open('student_msg','a', encoding='utf-8') as f:
        f.write(f"姓名：{name}  年龄：  {age} 地址： {adress}  性别： {sex}"+'\n')
while True:
        name = input("请输入姓名：")
        if name =="Q" or name == "q":
                     break
        sex = input("请输入性别：") or '男'
        age = input("请输入年龄：")
        adress = input("请输入地址：")
        shuai(name, age, adress, sex)
"""


            # def add_student_to_file(name, gender='男', age=None, address=None):
            #     # 构建学生信息字符串
            #     student_info = f"姓名: {name}, 性别: {gender}, 年龄: {age}, 地址: {address}\n"
            #
            #     # 将学生信息追加到文件
            #     with open('student_msg.txt', 'a') as file:
            #         file.write(student_info)
            #
            # # 循环接收用户输入，直到用户输入 'Q' 或 'q' 为止
            # while True:
            #     name = input("请输入姓名（输入 Q 或 q 退出）: ")
            #     if name.upper() == 'Q':
            #         break
            #
            #     gender = input("请输入性别（默认为男，直接回车使用默认值）: ") or '男'
            #     age = input("请输入年龄: ")
            #     address = input("请输入地址: ")
            #
            #     # 调用函数将学生信息追加到文件
            #     add_student_to_file(name, gender, age, address)
            #
            # print("输入结束，学生信息已追加到文件 'student_msg.txt' 中。")

# 打印功能菜单、添加学生信息、删除学生信息、修改学生信息、显示学生信息、退出系统，
# 并且需要接收用户的输入，在根据输入内容调用相应函数实现相应功能（存入文件），模板图如下。每次对学生管理系统发生改动，要写入改动点到log.txt文本中
#7
stuinfo=[]
while True:
    print("1.添加学生信息")
    print("2.删除学生信息")
    print("3.修改学生信息")
    print("4.显示学生信息")
    print("0.退出系统")
    an = input("请输入功能序号：")
    if an == "1":
        add_name = input("请输入要添加学生姓名:")
        if add_name not in stuinfo:
            stuinfo.append(add_name)
            with open('student_msg','w',encoding='utf-8')as f:
                for i in stuinfo:
                    f.write(i+'\n')
        else:
            print("您要添加的学生已存在！")
            print("本次添加失败！")
    elif an == "2":
        delete_name = input("请输入要删除的学生姓名：")
        if delete_name in stuinfo:
            stuinfo.remove(delete_name)
            with open('student_msg','w',encoding='utf-8')as f:
                    f.write(i+'\n')
        else:
            print("您要删除的学生不存在！")
            print("本次删除失败！")
    elif an == "3":
        change_oldname = input("请输入要修改之前的学习姓名：")
        change_newname = input("请输入修改之后的姓名：")
        if change_oldname in stuinfo:
            stuinfo.remove(change_oldname)
            stuinfo.append(change_newname)
            with open('student_msg','w',encoding='utf-8')as f:
                    f.write(i+'\n')
        else:
            print("您要修改的学生不存在！")
            print("本次修改失败！")
    elif an == "4":
        with open('student_msg', 'r', encoding='utf-8') as f:
            print(f.read())
    elif an == "0":
        print("退出信息系统！")
        break
























